#include "plugin_eventrecord.h"

/**
 * @brief plugin_eventrecord::initUi 初始化ui
 */
void plugin_eventrecord::initUi()
{
    static bool initFlag = true;
    if (initFlag)
    {
        initFlag = false;
        plugin_eventrecord_ui->verticalLayout->addWidget(&mEventRecordTable);
        // 信号绑定
        QObject::connect(&mEventRecordTable, &eventrecord_table::signalToForward,
                         this, [this](const QString &arg)
                         { emit messageFromPlugin(pluginName(), arg); });
    }
}

/**
 * @brief sendMessageToPlugin 接收来自其他任务的信息
 * @param msg
 */
void plugin_eventrecord::sendMessageToPlugin(const QString &msg)
{
    initUi();
    processJsonCommand(msg);
}

/**
 * @brief plugin_eventrecord::processJsonCommand 解析json字符串
 * @param jsonStr
 */
void plugin_eventrecord::processJsonCommand(const QString &jsonStr)
{
    QString err;
    if (false == mEventRecordTable.processJsonCommand(jsonStr, &err))
    {
        emit messageFromPlugin(pluginName(), err);
    }
}